<?php
require '../database/db.php';
require '../../../JPush/autoload.php';

$mysql = new mysql();

// 获取订单详情
$sql = "select * from goodsorders where ordersid=".$_REQUEST[ordersid];
$goodsorders = $mysql->getRow($sql);

// 获取订单详情 end

// 获取用户和商家
$userid = 'user'.$goodsorders[userid];
$sql = "select * from user where userid=".$goodsorders[userid];
$user = $mysql->getRow($sql);

$shopid = 'shop'.$goodsorders[shopid];
$sql = "select * from shop where shopid=".$goodsorders[shopid];
$shop = $mysql->getRow($sql);
// 获取用户和商家 end

// 信息提示
$state = $_REQUEST[state];
switch ($state) {
	case 0:
		$tip = "订单号(".$goodsorders[numbers].")有新的状态:待付款,请点击查看";
		break;
	
	case 1:
		$tip = "订单号(".$goodsorders[numbers].")有新的状态:待发货,请点击查看";
		break;

	case 2:
		$tip = "订单号(".$goodsorders[numbers].")有新的状态:已发货,请点击查看";
		break;

	case 3:
		$tip = "订单号(".$goodsorders[numbers].")有新的状态:待评价,请点击查看";
		break;
	
	case 4:
		$tip = "订单号(".$goodsorders[numbers].")有新的状态:退款售后,请点击查看";
		break;

	case 5:
		$tip = "订单号(".$goodsorders[numbers].")有新的状态:交易成功,请点击查看";
		break;

	case 6:
		$tip = "订单号(".$goodsorders[numbers].")有新的状态:交易关闭,请点击查看";
		break;

	case 7:
		$tip = "订单号(".$goodsorders[numbers].")有新的状态:货到付款,请点击查看";
		break;
}
// 信息提示 end
use JPush\Client as JPush;
$app_key = 'd9a373ba8a6dd4aab9c13976';
$master_secret = '455f8fff180ebdddf133abcb';
$client = new JPush($app_key, $master_secret);
// 给用户推送信息
$client->push()
    ->setPlatform(array('ios', 'android'))
    ->addTag($userid)
    // ->addAllAudience()
    ->setNotificationAlert($tip)
    ->send();
// 给用户推送信息 end

// 给商家推送信息
$client->push()
    ->setPlatform(array('ios', 'android'))
    ->addTag($shopid)
    // ->addAllAudience()
    ->setNotificationAlert($tip)
    ->send();
// 给商家推送信息 end